#!/usr/bin/env python
import commands, subprocess, re, time, sys, csv
from datetime import datetime
from os.path import exists

number_re = "+([0-9]+\.[01-9]+|[0-9]+)"

def get_result_elasped_time(log):
    try:
        #return re.findall('Elasped time : '+number_re, log)[0]
        val = re.findall('Total Elapsed Time : '+number_re, log)[0]
        fval = (float)(val)
        fval = 0.000001 * fval
        return str(fval)
    except:
        return '-'

log = open('./log.csv', 'w+')


for intervals in ['0']:
    for operations in ['1000','10000','100000','1000000']:
        log.write('operation '+operations+',4,8,12,16,20,24,28,32,\n')
        for pushRatio in ['0.25','0.5','0.75','1']:
            for version in ['CCoarseGrainedLockStack','CLockFreeStack','CEliminationBackoffStack']:  #'naive','TAS','TTAS','Exponential backoff','Anderson Queue lock'
                log.write(version+'-'+pushRatio+',');
                for participants in ['4','8','12','16','20','24','28','32']:
                    f = open('./log/'+version+'.'+participants+'-'+pushRatio+'-'+operations+'-'+intervals+'.log', 'r')
                    log_data = f.read()
                    ElapsedTime = get_result_elasped_time(log_data)
                    OPSperSEC = str(float(int(participants)*int(operations))/float(ElapsedTime))
                    log.write(OPSperSEC+',')
                log.write('\n')
log.close()

